public class Demo40 {
    public static void main(String[] args) {
        Object locker=new Object(); //定义一把锁
       Thread t1=new Thread(()->{
           synchronized (locker){
               System.out.println("线程1获取到lock");
               try {
                   locker.wait();
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
               System.out.println("线程1的wait被唤醒");
           }
       });
        Thread t2=new Thread(()->{
           synchronized (locker){
               System.out.println("线程2获取到lock");
               try {
                   locker.wait();
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
               System.out.println("线程2的wait被唤醒");
           }
        });
        Thread t3=new Thread(()->{
          synchronized (locker){
              System.out.println("线程3获取到lock");
              try {
                  locker.wait();
              } catch (InterruptedException e) {
                  throw new RuntimeException(e);
              }
              System.out.println("线程3的wait被唤醒");
          }
        });
        t1.start();
        t2.start();
        t3.start();
        Thread t4=new Thread(()->{
             synchronized (locker){
                 locker.notify();
             }
        });
        t4.start();
    }
}
